<template>
	<div id="contract_table">
		<el-table
			ref="multipleTable"
			:data="contracts"
			tooltip-effect="dark"
			style="width: 100%"
			@row-click="get_row_data"
			border
		>
			<el-table-column type="selection" width="40" header-align="center"></el-table-column>
            <el-table-column prop="contractNum" label="合同编号" width="160" header-align="center" align="center"></el-table-column>
			<el-table-column prop="theme" label="合同名称" width="160" header-align="center" align="center"></el-table-column>
			<el-table-column prop="customer.customerName" label="客户名称" header-align="center" align="center"></el-table-column>
			<el-table-column label="合同状态" width="100" header-align="center" align="center">
				<template slot-scope="scope">
					{{ scope.row.conState.name }}
				</template>
			</el-table-column>
			<el-table-column prop="totalMoney" label="合同金额" header-align="center" align="center"></el-table-column>
			<el-table-column label="回款金额" header-align="center" align="center">
				<template slot-scope="s">
					{{ s.row.returnMoney?s.row.returnMoney:0 }}
				</template>
			</el-table-column>
			<el-table-column label="欠款金额" header-align="center" align="center">
				<template slot-scope="scope">
					{{scope.row.totalMoney-scope.row.returnMoney}}
				</template>
			</el-table-column>
			<el-table-column prop="signTime" label="签约时间" header-align="center" align="center">
				<template slot-scope="scope"> 
					{{ scope.row.signTime | date_format }}
				</template>
			</el-table-column>
			<el-table-column prop="empSigner.empName" label="促成人员" header-align="center" align="center"></el-table-column>
			
		</el-table>
	</div>
</template>

<script>
import {formatTimeToStr} from "../../assets/format.js"

export default {
	name: 'contractTable',
	props: ['state', 'contracts', 'constates'],
	data() {
		return {
		}
	},
	methods:{
		// 获取表格一行对象赋值给row
		get_row_data(data){
            if(data.conState.id != 6){
                this.$parent.$parent.$parent.drawer = true
			    this.$parent.$parent.$parent.contract = this.global.copy_obj(data)
            }
		}
	},
	computed:{
		contractState_options(){
			let array = []
			this.constates.forEach(item => {
				let obj = {}
				obj.value = item.id
				obj.label = item.name
				array.push(obj)
			});
			return array
		}
	},
	filters:{
		date_format(time){
			let date = new Date(time)
			return formatTimeToStr(date, "yyyy-MM-dd")
		}
	}
}
</script>

<style>
#contract_table .el-select input[type="text"]{border: none !important;background-color:transparent; padding: 0px;}
</style>